<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>


            <a-col :xl='6' :lg='7' :md='8' :sm='24'>
              <a-form-item label='分拣日期' style='width: 100%;'>
<!--                <a-range-picker :style="{width: '100%'}"  format="YYYY-MM-DD"-->
<!--                                :placeholder="['开始时间', '结束时间']"-->
<!--                                v-model='rangePikerDate'-->
<!--                                @change="onQueryDateChange" />-->

                <a-date-picker v-model:value='queryParam.sDate' :valueFormat='dateFormat' style='width: 100%;'
                               placeholder='入库日期'  />
              </a-form-item>
            </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label="冷库"  >
              <a-select  v-model="queryParam.storehouse"    placeholder='请选择冷库'>
                <a-select-option v-for='d in hoseList' :key='d.id' :value='d.code'>{{ d.name }}</a-select-option>
              </a-select>
            </a-form-item>

          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
<!--      <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>-->
      <a-button type='primary' icon='download' @click="handleExportXls22('入库单汇总导出'+ queryParam.sDate )">导出打印单</a-button>
      <!--    <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader' :action='importExcelUrl'
                    @change='handleImportExcel'>
            <a-button type='primary' icon='import'>导入</a-button>
          </a-upload>
          <a-dropdown v-if='selectedRowKeys.length > 0'>
            <a-menu slot='overlay'>
              <a-menu-item key='1' @click='batchDel'>
                <a-icon type='delete' />
                删除
              </a-menu-item>
            </a-menu>
            <a-button style='margin-left: 8px'> 批量操作
              <a-icon type='down' />
            </a-button>
          </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref='table'
        size='middle'
        bordered
        rowKey=uuid
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'

        class='j-table-force-nowrap'
        :scroll='{ x: true}'
        @change='handleTableChange'>

        <template slot='state' slot-scope='text'>
          <div v-if='this.state==0' v-html='text'></div>
        </template>

        <span slot='state' slot-scope='text, record'>
          <span  v-if='text!=null && text!="" && text==0'>正常</span>
          <span  v-if='text!=null && text!="" && text==1' class='ant-tag-red' style='color:red;'>删除</span>
        </span>


        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='uploadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
<!--          <a @click='handleEdit(record)'>详情</a>

          <a-divider type='vertical' />-->
<!--          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>
      </a-table>
    </div>

    <flowerTagIn-modal ref='modalForm' @ok='modalFormOk'></flowerTagIn-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { downFile } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import FlowerTagInModal from './modules/FlowerTagInModal2'
import JDate from '@/components/jeecg/JDate.vue'
import { queryFlowerBase, ajaxGetDictItems, queryGreenhouseByPd ,getVarietyList} from '@/api/api'

export default {
  name: 'FlowerTagInList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
    FlowerTagInModal
  },
  data() {
    return {
      queryParam: {},
      rangePikerDate: [],
      dateFormat: 'YYYY-MM-DD',
      baseList: [], //基地信息
      greenhouseList: [], //大棚信息
      hoseList: [], //冷库
      classesList: [], //等级信息
      varietyList: [], //品类信息
      psfList: [], //打包规格
      lengthList: [], //长度信息
      varietyCode: "",
      description: '批量入库管理管理页面',
      // 表头
      columns: [
       {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        }, /*{
          title: '序号',
          align: 'center',
          width: 100,
          dataIndex: 'no',
          fixed:'left',
        },*/
        {
          title: '基地',
          align: 'center',
          width: 100,
          dataIndex: 'sourceBase_dictText'
        },
        {
          title: '地块',
          align: 'center',
          width: 100,
          dataIndex: 'sourceGreenhouse_dictText'
        },{
          title: '冷库',
          align: 'center',
          dataIndex: 'storehouse_dictText',
          width: 100,
        },
        {
          title: '采收产品',
          align: 'center',
          width: 100,
          dataIndex: 'variety'
        },{
          title: '编码',
          align: 'center',
          width: 100,
          dataIndex: 'varietyCode'
        },

        /* {
          title: '产品编号',
          align: 'center',
          width: 100,
          dataIndex: 'varietyCode'
        },*/
        {
          title: '打包规格',
          align: 'center',
          width: 70,
          dataIndex: 'packingSpecifications'
        },
        {
          title: '入库数量',
          align: 'center',
          width: 100,
          dataIndex: 'tagNum'
        },
        {
          title: '单位',
          align: 'center',
          width: 100,
          dataIndex: 'flowerPoleLength'
        },
        {
          title: '创建人',
          align: 'center',
          width: 100,
          dataIndex: 'createUser_dictText'
        },


       /* {
          title: '分拣日期',
          align: 'center',
          width: 100,
          dataIndex: 'sortTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },*/
       /* {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed:"right",
          width: 147,
          scopedSlots: { customRender: 'action' },

        }*/
      ],
      url: {
        list: '/flower/flowerCost/queryInListByDate',
        delete: '/flower/flowerTagIn/delete32222',
        deleteBatch: '/flower/flowerTagIn/deleteBatc2h22222',
        exportXlsUrl: '/flower/flowerTagIn/exportXlsForTemp',
        importExcelUrl: 'flower/flowerTagIn/importExcel22222'
      },

      dictOptions: {}
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created() {
    this.initBaseInfo()    //初始化基地信息
    // this.initVarietyList()//初始化产品信息
    // this.initClassifyDict()//初始化等级信息
    // this.initpsfDict()//初始化打包规格
    // this.initlengthDict()//
    this.hoseList =  JSON.parse( localStorage.getItem("ch_storehouse")?localStorage.getItem("ch_storehouse"):"[]")
  },
  methods: {
    initDictConfig() {
    },
    //初始化基地信息
    initBaseInfo() {
      queryFlowerBase().then((res) => {
        if (res.success) {
          this.baseList = res.result
        }
      })
    },


    onQueryDateChange(date, dateString){// 日期段选择改变时的回调
      this.queryParam.sDate = dateString[0]
      this.queryParam.eDate = dateString[1]
    },
    searchReset(){// 查询重置
      this.queryParam={}
      this.rangePikerDate=[]
    },
    handleExportXls22(fileName){
      // 导出
      let param = this.getQueryParams()
      let urlss = '/flower/flowerCost/exportXlsForTemp'
      downFile(urlss, param).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>